﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using LCTMoodle.Service;

namespace LCTMoodle.Models.ViewModels
{
    public class TraLoiViewModel : Model
    {
        public int ma { get; set; }
        public string noiDung { get; set; }
        public DateTime thoiDiemTao { get; set; }
        public NguoiDungViewModel nguoiTao { get; set; }
        public int danhGia { get; set; }
        public string chuoiMaNguoiDungDanhGiaTot { get; set; }
        public string chuoiMaNguoiDungDanhGiaXau { get; set; }
        public int trangThai { get; set; }
        public int maCauHoi { get; set; }

        public override void assignModel(SqlDataReader dr)
        {
            for (int i = 0; i < dr.FieldCount; i++)
            {
                switch (dr.GetName(i))
                {
                    case "Ma":
                        ma = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "NoiDung":
                        noiDung = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "MaCauHoi":
                        maCauHoi = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "ThoiDiemTao":
                        thoiDiemTao = (dr.IsDBNull(i)) ? DateTime.MinValue : dr.GetDateTime(i); break;
                    case "MaNguoiTao":
                        nguoiTao = (dr.IsDBNull(i)) ? null : NguoiDungService.layNguoiDungTheoMaNguoiDung(dr.GetInt32(i)); break;
                    case "DanhGia":
                        danhGia = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "ChuoiMaNguoiDungDanhGiaTot":
                        chuoiMaNguoiDungDanhGiaTot = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "ChuoiMaNguoiDungDanhGiaXau":
                        chuoiMaNguoiDungDanhGiaXau = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "TrangThai":
                        trangThai = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    default:
                        break;
                }
            }
        }
    }
}